module.exports = (function() {
    var nameSpace = "metroProject";
    var process = function(req, res, next) {
        var redis = require('redis');
        var redisClient = redis.createClient();
        var uid = req.cookies.uid || null;
        var path = require('path');

      
        if (uid) {
            redisClient.get(nameSpace + ':' + uid, (function(req, res, next) {
                return function(err, reply) {
                    if (err || !reply) {
                        res.redirect('/login');
                    } else {
                        //todo
                        //保持多少天不变
                        next();
                    }
                };
            })(req, res, next));
        } else {
            console.log('redirect to loggin page');
            res.redirect('/login');
            // res.sendFile(path.join(__dirname, 'index.html'));
        }
    };
    return process;
})();
